var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "react"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const React = require("react");
    class SpinerComponent extends React.Component {
        constructor(props) {
            super(props);
            let render = this.render;
            console.assert(render != null);
            this.render = () => {
                let { status } = this.state || {};
                status = status || "loading";
                if (status == "loading") {
                    return React.createElement("div", { className: "loading" }, "\u6570\u636E\u6B63\u5728\u52A0\u8F7D\u4E2D...");
                }
                else if (status == "fail") {
                    return React.createElement("div", { className: "empty", onClick: () => this._loadData() },
                        React.createElement("div", { className: "empty" }, "\u9875\u9762\u52A0\u8F7D\u5931\u8D25,\u70B9\u51FB\u91CD\u65B0\u52A0\u8F7D"));
                }
                return render.apply(this);
            };
            let componentDidMount = this.componentDidMount;
            this.componentDidMount = () => __awaiter(this, void 0, void 0, function* () {
                this._loadData();
                if (componentDidMount)
                    componentDidMount.apply(this);
            });
        }
        componentWillReceiveProps() {
            this._loadData();
        }
        _loadData() {
            return __awaiter(this, void 0, void 0, function* () {
                this.setState({ status: "loading" });
                try {
                    let s = yield this.loadData();
                    if (s == null) {
                        this.setState({ status: "fail" });
                    }
                    else {
                        s.status = "complete";
                        this.setState(s);
                    }
                }
                catch (err) {
                    this.setState({ status: "fail" });
                    console.error(err);
                }
            });
        }
    }
    exports.SpinerComponent = SpinerComponent;
});
